# Base R image
FROM rocker/r-ver:4.2.3

# Make a directory in the container

RUN apt-get update
RUN apt-get install zlib1g-dev
RUN apt-get -y install libpng-dev
RUN apt -y install texlive-latex-extra

# not sure installing these fonts is necessary
RUN apt update && apt install fonts-noto-cjk
RUN mkdir /home/r-environment
RUN mkdir /home/r-environment/figures
RUN mkdir /home/r-environment/figures/appendix_plots
RUN mkdir /home/r-environment/figures/paper_plots

# Install R dependencies

RUN Rscript -e "install.packages('tikzDevice')"
RUN Rscript -e "install.packages('fastDummies')"
RUN Rscript -e "install.packages('psych')"

RUN apt -y install libfontconfig1-dev
RUN apt -y  install libssl-dev
RUN apt -y install libxml2-dev
RUN apt -y install libcurl4-openssl-dev

RUN Rscript -e "install.packages('kableExtra')"
RUN Rscript -e "install.packages('gt')"
RUN Rscript -e "install.packages('gtsummary')"
RUN Rscript -e "install.packages('cjoint')"
RUN Rscript -e "install.packages('data.table')"
RUN Rscript -e "install.packages('stringr')"
RUN Rscript -e "install.packages('dplyr')"
RUN Rscript -e "install.packages('cregg')"
RUN Rscript -e "install.packages('estimatr')"
RUN Rscript -e "install.packages('formula.tools')"

RUN apt -y install cmake

RUN Rscript -e "install.packages('sjPlot')"
RUN Rscript -e "install.packages('patchwork')"
RUN Rscript -e "install.packages('ggplot2')"
RUN Rscript -e "install.packages('tidyr')"

RUN apt-get update
RUN apt-get -y install xorg


# Copy our R script to the container

COPY data/survey_one_sharefile.csv /home/r-environment/data/main_survey_final.csv
COPY data/survey_two_sharefile.csv /home/r-environment/data/follow_up_survey_rakuten.csv
COPY data/local_candidates.csv /home/r-environment/data/local_candidates.csv
COPY data/candidate_dataset.csv /home/r-environment/data/candidate_dataset.csv


COPY mappings /home/r-environment/mappings
COPY README.txt /home/r-environment/README.txt
COPY Codebook.pdf /home/r-environment/Codebook.pdf
COPY Dockerfile /home/r-environment/Dockerfile


COPY prepare_candidate_char_table.py /home/r-environment/prepare_candidate_char_table.py
COPY 1_format_first_survey.R /home/r-environment/1_format_first_survey.R
COPY 2_format_second_survey.R  /home/r-environment/2_format_second_survey.R
COPY 3_first_conjoint_mm_main_effects.R /home/r-environment/3_first_conjoint_mm_main_effects.R
COPY 4_second_experiment_main_effects.R  /home/r-environment/4_second_experiment_main_effects.R
COPY 5_treatment_effect_heterogeneity.R  /home/r-environment/5_treatment_effect_heterogeneity.R
COPY 6_university_ratings.R /home/r-environment/6_university_ratings.R
COPY 7_make_candidate_data_table.R /home/r-environment/7_make_candidate_data_table.R
COPY 8_no_carryover_assumption_tests_exp1.R /home/r-environment/8_no_carryover_assumption_tests_exp1.R
COPY 9_no_carryover_assumption_tests_exp2.R /home/r-environment/9_no_carryover_assumption_tests_exp2.R
COPY 10_make_descriptive_table.R /home/r-environment/10_make_descriptive_table.R
COPY 11_satisficer_check_main_survey.R /home/r-environment/11_satisficer_check_main_survey.R
COPY 12_satisficer_check_second_survey.R /home/r-environment/12_satisficer_check_second_survey.R

# Set UTF-8 for CJK recognition
RUN apt-get -y install locales
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && \
    locale-gen
ENV LANG en_US.UTF-8  
ENV LANGUAGE en_US:en  
ENV LC_ALL en_US.UTF-8

# Run the R script
WORKDIR "/home/r-environment/"
CMD Rscript -e "source('/home/r-environment/1_format_first_survey.R')" && \
Rscript -e "source('/home/r-environment/2_format_second_survey.R')" && \
Rscript -e "source('/home/r-environment/3_first_conjoint_mm_main_effects.R')"  && \
Rscript -e "source('/home/r-environment/4_second_experiment_main_effects.R')"  && \
Rscript -e "source('/home/r-environment/5_treatment_effect_heterogeneity.R')"  && \
Rscript -e "source('/home/r-environment/6_university_ratings.R')"  && \
Rscript -e "source('/home/r-environment/7_make_candidate_data_table.R')"  && \
Rscript -e "source('/home/r-environment/8_no_carryover_assumption_tests_exp1.R')"  && \
Rscript -e "source('/home/r-environment/9_no_carryover_assumption_tests_exp2.R')"  && \
Rscript -e "source('/home/r-environment/10_make_descriptive_table.R')"  && \
Rscript -e "source('/home/r-environment/11_satisficer_check_main_survey.R')"  && \
Rscript -e "source('/home/r-environment/12_satisficer_check_second_survey.R')"  



